#!usr/bin/python
# -*- coding:utf8 -*-
import os
import shutil
import time


class ShutilDemo:
    def _test_repr(self):
        """
        sd = ShutilDemo()
        sd._test_repr()
        """
        cur_time = repr(time.time())
        print cur_time

    def _test_query(self):
        """
        sd = ShutilDemo()
        sd._test_query()
        """
        origin_dir = os.getcwd()
        print origin_dir

        print os.curdir

        print os.sep

        print os.environ
        print os.getenv('pythonpath')

        os.putenv('user_path', 'c:/')
        print os.getenv('user_path')

        print os.path.isfile("C:/")

        print os.path.isdir("C:/")

        print os.path.isabs("C:/")

        print os.path.exists("C:/")

        print os.path.split("D:/Python/")

        print os.path.splitext("D:/Python/")

        print os.path.basename("D:/Python/")

        print os.path.dirname("D:/Python/")

        print os.path.abspath("D:/Python/")

    def _test_mkdir(self):
        """
        sd = ShutilDemo()
        sd._test_mkdir()
        """
        mkdir_name = "mkdir"
        os.mkdir(mkdir_name)
        print os.listdir(".")

    def _test_rename(self):
        """
        sd = ShutilDemo()
        sd._test_rename()
        """
        rendir_name = "rename"
        mkdir_name = "mkdir"
        os.rename(mkdir_name, rendir_name)
        print os.listdir(".")

    def _test_rmdir(self):
        """
        sd = ShutilDemo()
        sd._test_rmdir()
        """
        rmdir_name = "rename"
        os.rmdir(rmdir_name)
        print os.listdir(".")

    def _test_chdir(self):
        """
        sd = ShutilDemo()
        sd._test_chdir()
        """
        origin_dir = os.getcwd()
        os.chdir(origin_dir.split(os.sep)[0] + os.sep)
        print os.listdir(".")
        os.chdir(origin_dir)
        print os.listdir(".")

    def _test_copyfile(self):
        """
        sd = ShutilDemo()
        sd._test_copyfile()
        """
        # src和dst必须是文件，不可以是目录
        src_file = "./ext/cShutil/source.txt"
        tar_file = "./ext/cShutil/target.txt"
        shutil.copyfile(src_file, tar_file)
        print os.listdir(".")

    def _test_copy(self):
        """
        sd = ShutilDemo()
        sd._test_copy()
        """
        # src必须为文件，dst为文件或目录
        src_file = "./ext/cShutil/source.txt"
        tar_fileordir = "./ext/cShutil/src/"
        shutil.copy(src_file, tar_fileordir)
        print os.listdir(".")

    def _test_copytree(self):
        """
        sd = ShutilDemo()
        sd._test_copytree()
        """
        # src和dst必须为目录
        # 如果第3个参数是True，则复制目录时将保持文件夹下的符号连接，如果第3个参数是False，则将在复制的目录下生成物理副本来替代符号连接
        # 拷贝后的文件夹的最后访问时间、修改时间都是与原文件夹一样的
        # dst存在的话，是不可覆盖的
        src_dir = "./ext/cShutil/src/"
        tar_dir = "./ext/cShutil/target/"
        shutil.copytree(src_dir, tar_dir, False)
        print os.listdir(".")

    def _test_move(self):
        """
        sd = ShutilDemo()
        sd._test_move()
        """
        # src和dst必须为目录
        # dst可以覆盖
        src_dir = "./ext/cShutil/src/"
        tar_dir = "./ext/cShutil/target/"
        shutil.move(src_dir, tar_dir)
        print os.listdir(".")

    def _test_rmtree(self):
        """
        sd = ShutilDemo()
        sd._test_rmtree()
        """
        tar_dir = "./ext/cShutil/target/"
        shutil.rmtree(tar_dir)
        print os.listdir(".")


if __name__ == '__main__':
    sd = ShutilDemo()
    sd._test_rmtree()
